﻿@using Coralcode.Base.Entity
@using CoralNode.Core.Entity.Domains.User
@using CoralNode.Core.Entity.Enums
@using CoralNode.MvcClient.Helper
@using Coralcode.Utils.Basic
@using CoralNode.MvcClient.Contexts
@model CoralNode.Core.Entity.Domains.Site.SiteDomain


@Html.IncludePage("CoralAdmin/site", "_Left", new { current = "site" })
<style>
    .checkbox_own { margin-top: 12px; }
    .list_authoritylist ul li .checkbox_own { margin-top: 6px; }
</style>
@helper CountSitePermission(IList<PermissionDomain> permissionList) {
    int total = 0;
    foreach (var item in permissionList) {
        if (item.HasChildren == DomainEnums.Binary.True && item.Children != null) {
            foreach (var child in item.Children) {
                total += item.Roles.Count;
            }
        } else {
            total += item.Roles.Count;
        }
    }
    @(total)
}
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">网站设置&nbsp;&nbsp;/&nbsp;&nbsp;<b
                class=" t_small f_no">性能设置(@Model.Name)</b></span>
        </div>
        <div id="main">
            <div class="local">
                <a href="/m/site" class="ico ico_back btn"></a>
            </div>
            <div class="content_tab extra_normal">
                @Html.IncludePage("CoralAdmin/site", "_navtab", new { current = "performance", siteId = Model.Id })
            </div>
            <form action="/m/site/EditPerformance/@Model.Id" method="post" enctype="multipart/form-data">
                <div class="table_form form_main">
                    @if (@ViewBag.Msg != null) {
                        <div class="error_msg">
                            @ViewBag.Msg.Msg
                        </div>
                    }
                    <table data-js="tabCnt">
                        <tbody>
                            <tr>
                                <th width="60"><span class="info_txt">缓存：</span></th>
                                <td>
                                    <input type="button" class="btn_2 btn js_updatecache" value="更新缓存" />
                                </td>
                            </tr>
                            <tr>
                                <th width="80"><span class="info_txt">静态化：</span></th>
                                <td>
                                    <label class="mr_2">
                                        <input  type="checkbox" class="mt_0-5" value="@true.ToString()" name="IsStatic" @(Model.IsStatic ? "checked=checked" : string.Empty)/>开启静态化
                                    </label>

                                    @if (Model.IsStatic) {
                                        <input type="button" class="btn_2 btn js_updatestatistic" value="更新静态页" />    
                                    }
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="submitbox p_2 extra_normal">
                    <input type="submit" class="btn_1" value="提    交" />
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".js_updatecache").click(function () {
            $.post("/m/common/UpdateCache", function (data) {

                if (data != null && data) {
                    $.alert("更新成功！");
                }
                else {
                    $.alert("更新失败！", "error");
                }
            });
        });
        $(".js_updatestatistic").click(function () {
            $.post("/m/site/UpdateStaticPage/@Model.Id", function (data) {
                if (data != null && data == true) {
                    $.alert("更新成功！");
                } else {
                    $.alert("更新失败！", "error");
                }
            });
        });
    })
</script>
